package com.test.common;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.client.ClientFactory;
import com.netflix.config.ConfigurationManager;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.niws.client.http.RestClient;

@SpringBootApplication
@RestController
public class RibbonApplication2 {

	@RequestMapping("/")
	public void getServerList2() throws Exception {
		ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
		@SuppressWarnings("deprecation")
		RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
		@SuppressWarnings("rawtypes")
		ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client.getLoadBalancer();
		for (int i = 0; i < 10; i++) {
			Server server = lb.chooseServer();
			System.out.println(server.getHost() + "," + server.getPort());			
		}
	}

	public static void main(String[] args) {
		SpringApplication app = new SpringApplicationBuilder(RibbonApplication2.class).build();
		app.run(args);
	}

}